/**
  ******************************************************************************
  * @file    Devices_Coulometer.c
  * @author  AnshininTakaha
  * @version V1.21
  * @date		 2021/10/21
  * @brief   The File of the Coulometer Rules.
	* @copyright (c) 2017-2021 JZI. All rights reserved.
  ******************************************************************************
  */
/* Includes ------------------------------------------------------------------*/
#include "Coulometer.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/* Exported mention ----------------------------------------------------------*/
void USART5_Coulometer_IT_Init(void);
void Coulometer_Depkg(CoulometerReciver_t CR);
void Coulometer_DataRequest(void);

/* Exported variables --------------------------------------------------------*/
/* Coulometer Functions */
Coulometer_Fuc Coulometer_Functions = Coulometer_FucGroundInit;
#undef Coulometer_FucGroundInit

/* Coulometer Data Receiver */
CoulometerReciver_t CoulometerReceiver;

/* Coulometer Data After-Depkg Data */
CoulometerDepkg_t CoulometerDepkg;

/* Coulometer Stable Data Push Request */
uint8_t Coulometer_DataPushRequest[Coulometer_DataPushRequestLength] = \
{0x5A,0xA5,0x10,0x00,0x00,0x00,0x00,0x0F};
/* Exported functions --------------------------------------------------------*/
/**
 * @brief USART5 Init for Coulometer
 * @param  void.
 * @return void.
 */
void USART5_Coulometer_IT_Init(void)
{
	usart5_init(9600);
}



/**
 * @brief Depkg the Data from the Coulometer
 *        The Coulometer Data is not follow u16 Rules
 *        Depart and then Regroup the Data in Right Rules
 *        for Using.
 * @param  void.
 * @return void.
 */
void Coulometer_Depkg(CoulometerReciver_t CR)
{
	/* Depkg_VoltagePercentage */
	CoulometerDepkg.Depkg_VoltagePercentage = CR.VoltagePercentage;
	
	/* Depkg_Voltage */
	CoulometerDepkg.Depkg_Voltage = (((CR.Voltage_Upper * 0x100) + \
											 (CR.Voltage_Downer)) \
											 *0.01f);
	
	/* Depkg_Current */
	CoulometerDepkg.Depkg_Current = (((CR.Current_Upper * 0x100) + \
											 (CR.Current_Downer)) \
											 *0.01f);
	
	/* Depkg_RatedCapacity */
	CoulometerDepkg.Depkg_RatedCapacity = (((CR.RatedCapacity_Upper * 0x100) + \
											 CR.RatedCapacity_Downer) / 10);
	
	/* Depkg_Temperature(Our Coulometer has not Temperature Tracker) */
	CoulometerDepkg.Depkg_Temperature = (((CR.Temperature_Upper * 0x100) + \
											 (CR.Temperature_Downer)) \
											 *0.01f);
	
	/* Current Directions */
	CoulometerDepkg.Depkg_CurrentDirection = CR.CurrentDirection;
}



/**
 * @brief Send Coulometer Data Request
 * @param  void.
 * @return void.
 */
void Coulometer_DataRequest(void)
{
	/* Coulometer Data Request Command Send */
	send_data_dma_u5(Coulometer_DataPushRequest, \
					     sizeof(Coulometer_DataPushRequest));
	
}
/* End -----------------------------------------------------------------------*/


